﻿@echo off
chcp 65001 >nul
title 智能客服系统启动器

echo.
echo ========================================
echo    智能客服系统启动器
echo ========================================
echo.

echo [1/4] 检查并停止现有进程...
for /f "tokens=5" %%a in ('netstat -aon ^| findstr :5001') do (
    taskkill /f /pid %%a >nul 2>&1
)
for /f "tokens=5" %%a in ('netstat -aon ^| findstr :5000') do (
    taskkill /f /pid %%a >nul 2>&1
)
echo  清理完成

echo.
echo [2/4] 启动应用...
cd SmartCustomerService.Web
start /B dotnet run
echo  应用启动中...

echo.
echo [3/4] 等待应用完全启动...
timeout /t 8 /nobreak >nul

echo.
echo [4/4] 检查应用状态并打开浏览器...
:check_port
netstat -an | findstr :5001 >nul
if errorlevel 1 (
    echo 等待应用启动...
    timeout /t 2 /nobreak >nul
    goto check_port
)

echo  应用启动成功！

echo.
echo 正在打开浏览器...
start "" "https://localhost:5001/swagger"
timeout /t 1 /nobreak >nul
start "" "http://localhost:5000/swagger"

echo.
echo ========================================
echo    启动完成！
echo ========================================
echo.
echo  Swagger API 文档地址:
echo    HTTPS: https://localhost:5001/swagger
echo    HTTP:  http://localhost:5000/swagger
echo.
echo  如果浏览器没有自动打开，请手动访问上述地址
echo.
echo 按任意键退出此窗口（应用将继续运行）...
pause >nul
